from Monitor.NetworkMonitor import NetworkDelayMonitor,NetworkMonitor,MonitorType,NetworkBandWidthMonitor
from containernet.node import DockerSta
from OSM_Mininet_wifi.node import OSMDockerStaion,OSMDockerCloud
from containernet.cli import CLI
from containernet.term import makeTerm
from mininet.log import info, setLogLevel,output
from mn_wifi.mobility import Mobility
from mininet.node import Controller
from OSM_Mininet_wifi.net import OSM_Mininet_wifi
from mn_wifi.net import OVSKernelAP

setLogLevel('info')
net = OSM_Mininet_wifi(controller=Controller,autoAssociation=False)


net.addAccessPoint(**{'type': 'bs', 'name': 'bs0', 'location': [28.19917452786327, 112.96940803527833], 'position': [132, 86, 0], 'ssid': 'ssid-bs0', 'ip': '10.0.0.1/8', 'ip6': '2001:0:0:0:0:0:0:1/64', 'mac': '00:00:00:00:00:01', 'range': 500, 'failMode': 'standalone'})
net.addAccessPoint(**{'type': 'bs', 'name': 'bs1', 'location': [28.19535456710196, 112.97487974166872], 'position': [669, -339, 0], 'ssid': 'ssid-bs1', 'ip': '10.0.0.2/8', 'ip6': '2001:0:0:0:0:0:0:2/64', 'mac': '00:00:00:00:00:02', 'range': 500, 'failMode': 'standalone'})
net.addStation(**{'type': 'mp', 'name': 'mp0', 'location': ['28.19460084229876,112.97526168829792', '28.197077123458822,112.96830940253132'], 'position': '706,-422,0', 'ip': '10.0.0.3/8', 'ip6': '2001:0:0:0:0:0:0:3/64', 'mac': '00:00:00:00:00:03', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['712,-418,0', '875,-453,0', '878,-442,0', '714,-406,0', '701,-404,0', '475,-393,0', '407,-389,0', '356,-386,0', '296,-383,0', '275,-382,0', '263,-381,0', '232,-378,0', '217,-377,0', '179,-375,0', '176,-162,0', '76,-143,0', '23,-142,0'], 'distance': 1247.7956486020062}, 'node': 'mp0'})
net.addStation(**{'type': 'mp', 'name': 'mp1', 'location': ['28.20055516193482,112.9682879448592', '28.196510041235452,112.9779224396407'], 'position': '23,240,0', 'ip': '10.0.0.4/8', 'ip6': '2001:0:0:0:0:0:0:4/64', 'mac': '00:00:00:00:00:04', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['19,252,0', '21,208,0', '113,210,0', '108,195,0', '176,194,0', '176,223,0', '183,239,0', '258,237,0', '261,180,0', '265,90,0', '266,64,0', '267,23,0', '279,23,0', '295,22,0', '388,19,0', '542,12,0', '568,10,0', '720,4,0', '717,-157,0', '731,-158,0', '823,-173,0', '901,-185,0', '962,-204,0'], 'distance': 1420.1188254603821}, 'node': 'mp1'})
net.addDocker(**{'type': 'ec', 'name': 'ec0', 'location': [28.195716121067544, 112.97635602957601], 'position': [813, -298, 0], 'ip': '10.0.0.5/8', 'ip6': '2001:0:0:0:0:0:0:5/64', 'mac': '00:00:00:00:00:05', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.addDocker(**{'type': 'ec', 'name': 'ec1', 'location': [28.199950293809778, 112.970412254399], 'position': [231, 172, 0], 'ip': '10.0.0.6/8', 'ip6': '2001:0:0:0:0:0:0:6/64', 'mac': '00:00:00:00:00:06', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.startController(**{'controller': 'None', 'name': 'c', 'number': 1, 'ip': '127.0.0.1', 'port': 6653, 'protocol': 'tcp', 'app': 'simple_switch'})
net.configureWifiNodes()
net.addLink(**{'type': 'nl', 'node1': 'bs1', 'node2': 'ec0', 'delay': '30ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.addLink(**{'type': 'nl', 'node1': 'bs0', 'node2': 'ec1', 'delay': '5ms', 'bw': 20, 'jitter': '0ms', 'loss': 0})
net.OSM_Mobility_Setting(**{'mobility_start_time': 1, 'reverse': 1, 'ac_method': 'ssf', 'mob_rep': 1, 'mobility_mode': 'quickly'})
net.start()
thread_list = []
t=NetworkDelayMonitor('mp0', 'ec0', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220400916783.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkDelayMonitor('mp0', 'ec1', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220400916783.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkBandWidthMonitor('mp1', 'ec0', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220400916783.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkBandWidthMonitor('mp1', 'ec1', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220400916783.json',**{'period': 60}).thread_
thread_list.append(t)
for td in thread_list: td.join()
net.OSM_Experiment_Ended(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220400916783.json')
net.stop()
